﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Collections;
using Model;

namespace Controller
{
    public class cntrUf
    {
        public cntrUf()
        {
        }

        Uf objUf;

        #region Metodos

        #region Salvar
        public Boolean Save(DS_Lawyer.UfRow pUf)
        {
            Boolean flagReturn = false;
            if (pUf.idUf == string.Empty)
            {
                this.objUf = new Uf();
                this.objUf.IdUF = System.Guid.NewGuid().ToString();
                this.objUf.CodUf = pUf.codUf;
                this.objUf.Nome = pUf.nome;

                try
                {
                    flagReturn = this.objUf.Persist();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                this.objUf = Uf.RetriveObject(pUf.idUf);
                this.objUf.Nome = pUf.nome;

                try
                {
                    flagReturn = this.objUf.Update();
                }
                catch (Exception ex)
                {

                    throw ex;
                }
            }
            return flagReturn;
        }
        #endregion

        #region Select
        public static DS_Lawyer.UfDataTable Select()
        {
            DS_Lawyer.UfDataTable dtUf = new DS_Lawyer.UfDataTable();
            try
            {
                IList listUFs = Uf.RetriveObjects();
                for (int i = 0; i < listUFs.Count; i++)
                {
                    Uf objUf = (Uf)listUFs[i];
                    dtUf.AddUfRow(objUf.CodUf, objUf.Nome, objUf.IdUF);
                }
            }
            catch (Exception ex)
            {
                //Tratar mensagem de erro aqui!
                throw ex;

            }
            return dtUf;
        }
        #endregion

        #endregion
            
    }

    
}
